﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Power_add : BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            CMSModel.CMSEntities dal = DAL.DBManager.GetCmsEmtity();
            ddlPid.DataSource = dal.Power;
            ddlPid.Items.Insert(0, new ListItem("--请选择--", ""));
            ddlPid.Items.Insert(1,new ListItem("一级菜单","0"));
            ddlPid.DataBind();
        }
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        CMSModel.CMSEntities dal = DAL.DBManager.GetCmsEmtity();
        CMSModel.Power power = new CMSModel.Power();
        power.Id = txtId.Text;
        power.Name = txtName.Text;
        power.Pid = ddlPid.SelectedValue;
        power.Url = txtUrl.Text;
        if(rbtnForbidden.Checked)
            power.IsEnable = false;
        else
            power.IsEnable = true;
        try
        {
            dal.AddToPower(power);
            dal.SaveChanges();
            ClientScript.RegisterStartupScript(GetType(), "save", "alert('添加成功'),document.location='Default.aspx'", true);
        }
        catch (Exception ex)
        {
            LogYuMin.LogWriter.GetWriter(LogYuMin.LogFile.error).Write(GetType(), "addPower", LogYuMin.LogStates.ERROR, ex);
            ClientScript.RegisterStartupScript(GetType(), "save", "alert('添加失败')", true);
        }
    }
}